package com.mapeditor.graph{
/**
* Classe da grid de plano de fundo
* @author Osvaldo Cassaniga Junior
* @version 1.0
*/

  import com.mapeditor.util.GlobalContainer;
  import flash.display.Sprite;
  
  public class BackgroundGrid extends Sprite{
       public var nrX:Number;
       public var nrY:Number;
       
       public function BackgroundGrid(){
          nrX = 0;
          nrY = 0;
      }//end of Method
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       /**
       Desenha
       */              
      public function draw(w:Number,h:Number):void{           
			this.graphics.lineStyle(1,0xE8E8E8);
			//move para o ponto inicial
			this.graphics.moveTo(0,0);			
			
			nrX = Math.floor(w/20);
			for(var c:int = 0; c < nrX+1; c++){
				this.graphics.moveTo(c*GlobalContainer.sizeGrid,0);			
				this.graphics.lineTo(c*GlobalContainer.sizeGrid,h);				
			}
			nrY = Math.floor(h/GlobalContainer.sizeGrid);
			for(var l:int = 0; l < nrY+1; l++){
				this.graphics.moveTo(0,   l*GlobalContainer.sizeGrid);			
				this.graphics.lineTo(w,l*GlobalContainer.sizeGrid);				
			}
		  
      }//end of Method
      public function redraw(w:Number,h:Number):void{
		if (Math.floor(w/GlobalContainer.sizeGrid) != nrX || Math.floor(h/GlobalContainer.sizeGrid) != nrY)
		{
			this.graphics.clear();
			this.draw(w, h);  
		}
		
	  }
	  
	  public function clear():void{
		  	this.graphics.clear();
	  }
		  
      
    }//end of class
}
